﻿#include "QmlSignal.h"

QMLSignal::QMLSignal()
{

}


QMLSignal& QMLSignal::I(){
    static QMLSignal instance;
    return instance;
}


/**
 * @brief 发送故障信号，测试用
 */
void QMLSignal::sendErrorMsg_Union(){
    emit sendErrorMsg("测试的并发故障", "是", "1", 1);
}
void QMLSignal::sendErrorMsg_Process(){
    emit sendErrorMsg("测试的流程", "是", "1", 0);
}


/**
 * @brief QMLSignal::emitExperimentStatus 发送实验状态
 * @param type 类型
 * @param status 状态
 */
void QMLSignal::emitExperimentStatus(int type, int status,QString msg){
    __LOG_INFO("SIGNAL-ExpStatusChanged "+ QString::number(type) + " " + QString::number(status) + " msg:" + msg);
    emit experimentStatus(type,status,msg);
}

/**
 * @brief QMLSignal::emitRefExperimentLog 通知前端刷新实验日志
 * @param step 当前步骤
 */
void QMLSignal::emitRefExperimentLog(int step){
    __LOG_INFO("SIGNAL-ExpStepChanged "+QString::number(step));
    emit refExperimentLog(step);
}

/**
 * @brief QMLSignal::emitCommunicationStatus 通知前端当前通信状态
 * @param status
 */
void QMLSignal::emitCommunicationStatus(int status){
    __LOG_INFO("SIGNAL-ConnectStatusChanged "+QString::number(status));
    emit communicationStatus(status);
}

/**
 * @brief QMLSignal::emitVoiceAssistant 通知前端当前语音助手状态
 * @param status
 */
void QMLSignal::emitVoiceAssistant(int status){
    __LOG_INFO("SIGNAL-VoiceStatusChanged "+QString::number(status));
    emit voiceAssistant(status);
}

/**
 * @brief QMLSignal::emitVoiceAssistant 通知前端当前能谱连接状态
 * @param status
 */
void QMLSignal::emitEnergySpectrumStatus(int status){
    __LOG_INFO("SIGNAL-VoiceStatusChanged "+QString::number(status));
    emit energySpectrumStatus(status);
}

/**
 * @brief QMLSignal::emitRefCommunicationLog 通知前端刷新通信日志
 */
void QMLSignal::emitRefCommunicationLog(){
    // __LOG_INFO("SIGNAL-RefommunicationLog");
    emit refCommunicationLog();
}

/**
 * @brief QMLSignal::emitSendErrorMsg 向前端发送错误信息
 * @param errorInfo
 * @param methodInfo
 * @param errorModule
 */
void QMLSignal::emitSendErrorMsg(QString errorInfo,QString methodInfo,QString errorModule, int errorType){
    __LOG_INFO("SIGNAL-ErrorMsg "+errorInfo + " " + methodInfo + " " + errorModule + " " + errorType);
    emit sendErrorMsg(errorInfo,methodInfo,errorModule,errorType);
}

/**
 * @brief QMLSignal::emitSendResetMsg 向前端发送复位信息
 * @param status
 * @param serial
 */
void QMLSignal::emitSendResetMsg(QString status,int serial){
    __LOG_INFO("SIGNAL-ResetStatusChanged Status:"+status+" Serial:"+QString::number(serial));
    emit sendResetMsg(status,serial);
}

/**
 * @brief QMLSignal::emitSendSyringRunMsg 向前端发送注射器运动信息
 * @param status
 * @param serial
 */
void QMLSignal::emitSendSyringRunMsg(QString status, QString serial)
{
    __LOG_INFO("SIGNAL-SendSyringeRunMsg "+status+" "+serial);
    emit sendSyringRunMsg(status,serial);
}

/**
 * @brief QMLSignal::emitSyringDataLack 通知前端注射器信息缺失
 */
void QMLSignal::emitSyringDataLack()
{
    __LOG_INFO("SIGNAL-SyringeDataLack");
    emit syringDataLack();
}

/**
 * @brief QMLSignal::emitSendAirPumpPressure 发送气泵压力值
 * @param openVal
 * @param closeVal
 */
void QMLSignal::emitSendAirPumpPressure(QString openVal,QString closeVal){
    __LOG_INFO("SIGNAL-SendAirPumpPressure "+openVal + " " + closeVal);
    emit sendAirPumpPressure(openVal,closeVal);
}

/**
 * @brief QMLSignal::emitSendTurnTablePos 发送转盘位置参数
 * @param turnTableVal
 */
void QMLSignal::emitSendTurnTablePos(QString turnTableVal)
{
    __LOG_INFO("SIGNAL-SendTurnTablePos "+turnTableVal);
    emit sendTurnTablePos(turnTableVal);
}

/**
 * @brief QMLSignal::emitModuleFinish 模块实验完成
 * @param module
 */
void QMLSignal::emitModuleFinish(int module){
    __LOG_INFO("SIGNAL-ModuleFinishedChanged "+QString::number(module));
    emit moduleFinish(module);
}

/**
 * @brief QMLSignal::emitModuleCurrent 当前实验模块
 * @param module
 */
void QMLSignal::emitModuleCurrent(int module){
    __LOG_INFO("SIGNAL-ModuleCurrentChanged "+QString::number(module));
    emit moduleCurrent(module);
}

/**
 * @brief QMLSignal::emitStepRunningStatus 步骤执行状态
 * @param status
 */
void QMLSignal::emitStepRunningStatus(int status){
    __LOG_INFO("SIGNAL-StepRunningStatus "+QString::number(status));
    emit stepRunningStatus(status);
}

/**
 * @brief QMLSignal::emitGetHeliumGasPump 氦气泵压力值
 * @param pressureValue
 */
void QMLSignal::emitGetHeliumGasPump(QString pressureValue){
    emit getHeliumGasPump(pressureValue);
}

/**
 * @brief QMLSignal::emitGetSuctionCupPressure 吸盘气压
 * @param suctionCupValue
 */
void QMLSignal::emitGetSuctionCupPressure(QString suctionCupValue){
    emit getSuctionCupPressure(suctionCupValue);
}

/**
 * @brief QMLSignal::emitGetMotorPosition 读取电机位置
 * @param motorPos
 */
void QMLSignal::emitGetMotorPosition(QString motorPos){
    emit getMotorPosition(motorPos);
}

/**
 * @brief QMLSignal::emitGetScrewCapInfo 盖盖
 * @param speed
 * @param step
 */
void QMLSignal::emitGetScrewCapInfo(QString speed,QString step){
    emit getScrewCapInfo(speed,step);
}

/**
 * @brief QMLSignal::emitSendTargetAirPumpPressure 打靶气泵压力
 * @param airValue
 */
void QMLSignal::emitSendTargetAirPumpPressure(QString airValue){
    emit sendTargetAirPumpPressure(airValue);
}

/**
 * @brief QMLSignal::emitfbGetAir 空压机气压读取
 * @param airValue
 */
void QMLSignal::emitfbGetAir(QString airValue){
    emit fbGetAir(airValue);
}

/**
 * @brief QMLSignal::emitdbhqGetAir 氦气气压读取
 * @param airValue
 */
void QMLSignal::emitdbhqGetAir(QString airValue){
    emit dbhqGetAir(airValue);
}

/**
 * @brief QMLSignal::emitdbcgqsl 传感器数量
 * @param airValue
 */
void QMLSignal::emitdbcgqsl(QString cgqsl){
    emit dbcgqsl(cgqsl);
}

/**
 * @brief QMLSignal::emitdblsjyl 冷水机压力
 * @param airValue
 */
void QMLSignal::emitdblsjyl(QString lsjyl){
    emit dblsj(lsjyl);
}

/**
 * @brief QMLSignal::emitdbxqbGetAir 吸取靶气压读取
 * @param airValue
 */
void QMLSignal::emitdbxqbGetAir(QString airValue){
    emit dbxqbGetAir(airValue);
}

/** 干燥维护
 * @brief QMLSignal::emitdbGzwh
 * @param airValue
 */
void QMLSignal::emitdbGzwh(){
    emit dbGzwh();
}

/** 吸盘气压读取
 * @brief QMLSignal::emitzbxpGetAir
 * @param airValue
 */
void QMLSignal::emitzbxpGetAir(QString airValue1,QString airValue2){
    emit zbxpGetAir(airValue1,airValue2);
}

/** Z轴电机位置读取
 * @brief QMLSignal::emitzbZZ
 * @param wz
 */
void QMLSignal::emitzbZZ(QString sd,QString wz){
    emit zbZZ(sd,wz);
}

/** X轴电机位置读取
 * @brief QMLSignal::emitzbXZ
 * @param wz
 */
void QMLSignal::emitzbXZ(QString sd,QString wz){
    emit zbXZ(sd,wz);
}

/** 开盖电机位置读取
 * @brief QMLSignal::emitzbKG
 * @param wz
 */
void QMLSignal::emitzbKG(QString sd,QString wz){
    emit zbKG(sd,wz);
}

/** 活性电机位置读取
 * @brief QMLSignal::emitzbHX
 * @param wz
 */
void QMLSignal::emitzbHX(QString sd,QString wz){
    emit zbHX(sd,wz);
}

/** 活性电机位置读取
 * @brief QMLSignal::emitzbXPDJ
 * @param wz
 */
void QMLSignal::emitzbXPDJ(QString sd,QString wz){
    emit zbXPDJ(sd,wz);
}

/** 开盖电机位置读取
 * @brief QMLSignal::emitzbKG
 * @param wz
 * @param sd
 */
void QMLSignal::emitzbRD(QString wz,QString sd){
    double sd1 = sd.toDouble()/100;
    emit zbRD(wz,QString::number(sd1,'f',2));
}

/** 纯化电机参数配置
 * @brief QMLSignal::emitchDJCS
 * @param bzxf 步骤细分
 * @param yxdl 运行电流
 * @param djdl 待机电流
 */
void QMLSignal::emitchDJCS(QString bzxf,QString yxdl,QString djdl){
    emit chDJCS(bzxf,yxdl,djdl);
}

/** 纯化电机最大行程
 * @brief QMLSignal::emitchDJCS
 * @param bzxf 最大行程
 */
void QMLSignal::emitchDJMAX(QString maxxc){
    emit chDJMAX(maxxc);
}

/** 继续实验信息
 * @brief QMLSignal::emitSendExistExp
 * @param module
 * @param step
 * @param actionInfo
 * @param nextModule
 * @param nextStep
 * @param nextActionInfo
 */
void QMLSignal::emitSendExistExp(int module,int step,QString actionInfo,int nextModule,int nextStep,QString nextActionInfo)
{
    __LOG_INFO("SIGNAL-SendExistExp " + QString::number(module) + " " + QString::number(step) + " " + actionInfo + QString::number(nextModule) + " " + QString::number(nextStep) + " " + nextActionInfo);
    emit sendExistExp(module,step,actionInfo,nextModule,nextStep,nextActionInfo);
}

/** 接收数据超时
 * @brief QMLSignal::emitReceiveMsgOutTime
 */
void QMLSignal::emitReceiveMsgOutTime(){
    __LOG_INFO("SIGNAL-ReceiveMsgOutTime");
    emit receiveMsgOutTime();
}

/** 获取实验信息
 * @brief QMLSignal::emitGetExperimentInfo
 */
void QMLSignal::emitGetExperimentInfo(){
    emit getExperimentInfo();
}

/** 发送网络信息
 * @brief QMLSignal::emitSendConnectInfo
 */
void QMLSignal::emitSendConnectInfo(QString ip, QString port){
    emit sendConnectInfo(ip,port);
}

/** 测试信号
 * @brief QMLSignal::testEmitSignal
 */
void QMLSignal::testEmitSignal(){
    emitSendErrorMsg("1-37 S14送把到位\n", "是", "2",0);
    QTimer::singleShot(1500, [this](){
        emitSendErrorMsg("送靶位置异常", "否", "2",0);
    });
}

/** 暂停确认
 * @brief QMLSignal::emitSendPauseConfirmation
 */
void QMLSignal::emitSendPauseConfirmation(){
    emit sendPauseConfirmation();
}

/** 放靶气泵压力值
 * @brief QMLSignal::emitTargetGasPumpValue
 * @param value
 */
void QMLSignal::emitTargetGasPumpValue(QString value){
    emit targetGasPumpValue(value);
}

/** 转靶吸盘压力值
 * @brief QMLSignal::emitTargetGasPumpValue
 * @param value
 */
void QMLSignal::emitTargetPadPumpValue(QString value){
    emit targetPadPumpValue(value);
}

/** 打靶气泵压力值
 * @brief QMLSignal::emitTargetAirPumpValue
 * @param value
 */
void QMLSignal::emitTargetAirPumpValue(QString value){
    emit targetAirPumpValue(value);
}

/** 打靶氦气压力值
 * @brief QMLSignal::emitTargetAirPumpValue
 * @param value
 */
void QMLSignal::emitTargetArgonPumpValue(QString value){
    emit targetArgonPumpValue(value);
}

/** 打靶氦气压力值
 * @brief QMLSignal::emitInfolist
 * @param value
 */
void QMLSignal::emitInfolist(QStringList value){
    emit infolist(value);
}

/** 发送能谱数据
 * @brief QMLSignal::emitSendCpsData
 * @param cpsData 能谱数据
 */
void QMLSignal::emitSendCpsData(double cpsData){
    emit sendCpsData(cpsData);
}

void QMLSignal::emitSendRadiationData(int module, double radiationData){
    emit sendRadiationData(module,radiationData);
}

void QMLSignal::emitSendMessage(QString message){
    emit sendMessage(message);
}

void QMLSignal::emitNeedReset(){
    emit needReset();
}

/** 摄像头是否连连接成功
 * @brief 摄像头是否连连接成功
 * @param connState bool是否连接成功
 */
void QMLSignal::emitCameraConnect(bool connState){
    emit cameraConnect(connState);
}

void QMLSignal::emitRefreshJFCamera(int param2, void *pUserData){
    emit refreshJFCamera(param2, pUserData);
}

void QMLSignal::emitPartDetectorStatus(int type, int status){
    emit partDetectorStatus(type,status);
}

void QMLSignal::emitUnionStatus(int status){
    emit unionStatus(status);
}
